home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / xcmd / cliptoic.cpt / clipToICON XCMD / cards.xml < prev    next >
Encoding:
Text File  |  1991-10-26  |  10.9 KB  |  194 lines

  1. card_2847.xml
  2. <?xml version="1.0" encoding="utf-8" ?>
  3. <!DOCTYPE card PUBLIC "-//Apple, Inc.//DTD card V 2.0//EN" "" >
  4. <card>
  5.     <id>2847</id>
  6.     <filler1>0</filler1>
  7.     <bitmap>BMAP_2249.pbm</bitmap>
  8.     <cantDelete> <false /> </cantDelete>
  9.     <showPict> <true /> </showPict>
  10.     <dontSearch> <false /> </dontSearch>
  11.     <owner>2726</owner>
  12.     <link rel="stylesheet" type="text/css" href="stylesheet_3106.css" />
  13.     <part>
  14.         <id>1</id>
  15.         <type>field</type>
  16.         <visible> <true /> </visible>
  17.         <dontWrap> <false /> </dontWrap>
  18.         <dontSearch> <false /> </dontSearch>
  19.         <sharedText> <false /> </sharedText>
  20.         <fixedLineHeight> <false /> </fixedLineHeight>
  21.         <autoTab> <false /> </autoTab>
  22.         <lockText> <false /> </lockText>
  23.         <rect>
  24.             <left>19</left>
  25.             <top>304</top>
  26.             <right>81</right>
  27.             <bottom>332</bottom>
  28.         </rect>
  29.         <style>transparent</style>
  30.         <autoSelect> <false /> </autoSelect>
  31.         <showLines> <false /> </showLines>
  32.         <wideMargins> <false /> </wideMargins>
  33.         <multipleLines> <false /> </multipleLines>
  34.         <reservedFamily> 0 </reservedFamily>
  35.         <titleWidth>0</titleWidth>
  36.         <icon>0</icon>
  37.         <textAlign>right</textAlign>
  38.         <font>Palatino</font>
  39.         <textSize>10</textSize>
  40.         <textStyle>plain</textStyle>
  41.         <textHeight>13</textHeight>
  42.         <name></name>
  43.         <script></script>
  44.     </part>
  45.     <part>
  46.         <id>6</id>
  47.         <type>button</type>
  48.         <visible> <false /> </visible>
  49.         <reserved5> 0 </reserved5>
  50.         <reserved4> 0 </reserved4>
  51.         <reserved3> 0 </reserved3>
  52.         <reserved2> 0 </reserved2>
  53.         <reserved1> 0 </reserved1>
  54.         <enabled> <true /> </enabled>
  55.         <rect>
  56.             <left>89</left>
  57.             <top>301</top>
  58.             <right>123</right>
  59.             <bottom>302</bottom>
  60.         </rect>
  61.         <style>rectangle</style>
  62.         <showName> <false /> </showName>
  63.         <highlight> <false /> </highlight>
  64.         <autoHighlight> <false /> </autoHighlight>
  65.         <sharedHighlight> <true /> </sharedHighlight>
  66.         <family>0</family>
  67.         <titleWidth>0</titleWidth>
  68.         <icon>0</icon>
  69.         <textAlign>center</textAlign>
  70.         <font>Chicago</font>
  71.         <textSize>12</textSize>
  72.         <textStyle>plain</textStyle>
  73.         <name>topBorder</name>
  74.         <script></script>
  75.     </part>
  76.     <part>
  77.         <id>7</id>
  78.         <type>button</type>
  79.         <visible> <true /> </visible>
  80.         <reserved5> 0 </reserved5>
  81.         <reserved4> 0 </reserved4>
  82.         <reserved3> 0 </reserved3>
  83.         <reserved2> 0 </reserved2>
  84.         <reserved1> 0 </reserved1>
  85.         <enabled> <true /> </enabled>
  86.         <rect>
  87.             <left>90</left>
  88.             <top>334</top>
  89.             <right>123</right>
  90.             <bottom>335</bottom>
  91.         </rect>
  92.         <style>rectangle</style>
  93.         <showName> <false /> </showName>
  94.         <highlight> <false /> </highlight>
  95.         <autoHighlight> <false /> </autoHighlight>
  96.         <sharedHighlight> <true /> </sharedHighlight>
  97.         <family>0</family>
  98.         <titleWidth>0</titleWidth>
  99.         <icon>0</icon>
  100.         <textAlign>center</textAlign>
  101.         <font>Chicago</font>
  102.         <textSize>12</textSize>
  103.         <textStyle>plain</textStyle>
  104.         <name>bottomBorder</name>
  105.         <script></script>
  106.     </part>
  107.     <part>
  108.         <id>8</id>
  109.         <type>button</type>
  110.         <visible> <true /> </visible>
  111.         <reserved5> 0 </reserved5>
  112.         <reserved4> 0 </reserved4>
  113.         <reserved3> 0 </reserved3>
  114.         <reserved2> 0 </reserved2>
  115.         <reserved1> 0 </reserved1>
  116.         <enabled> <true /> </enabled>
  117.         <rect>
  118.             <left>89</left>
  119.             <top>302</top>
  120.             <right>90</right>
  121.             <bottom>335</bottom>
  122.         </rect>
  123.         <style>rectangle</style>
  124.         <showName> <false /> </showName>
  125.         <highlight> <false /> </highlight>
  126.         <autoHighlight> <false /> </autoHighlight>
  127.         <sharedHighlight> <true /> </sharedHighlight>
  128.         <family>0</family>
  129.         <titleWidth>0</titleWidth>
  130.         <icon>0</icon>
  131.         <textAlign>center</textAlign>
  132.         <font>Chicago</font>
  133.         <textSize>12</textSize>
  134.         <textStyle>plain</textStyle>
  135.         <name>leftBorder</name>
  136.         <script></script>
  137.     </part>
  138.     <part>
  139.         <id>9</id>
  140.         <type>button</type>
  141.         <visible> <true /> </visible>
  142.         <reserved5> 0 </reserved5>
  143.         <reserved4> 0 </reserved4>
  144.         <reserved3> 0 </reserved3>
  145.         <reserved2> 0 </reserved2>
  146.         <reserved1> 0 </reserved1>
  147.         <enabled> <true /> </enabled>
  148.         <rect>
  149.             <left>122</left>
  150.             <top>301</top>
  151.             <right>123</right>
  152.             <bottom>334</bottom>
  153.         </rect>
  154.         <style>rectangle</style>
  155.         <showName> <false /> </showName>
  156.         <highlight> <false /> </highlight>
  157.         <autoHighlight> <false /> </autoHighlight>
  158.         <sharedHighlight> <true /> </sharedHighlight>
  159.         <family>0</family>
  160.         <titleWidth>0</titleWidth>
  161.         <icon>0</icon>
  162.         <textAlign>center</textAlign>
  163.         <font>Chicago</font>
  164.         <textSize>12</textSize>
  165.         <textStyle>plain</textStyle>
  166.         <name>rightBorder</name>
  167.         <script></script>
  168.     </part>
  169.     <content>
  170.         <layer>background</layer>
  171.         <id>4</id>
  172.         <text>clipToICON XCMD</text>
  173.     </content>
  174.     <content>
  175.         <layer>background</layer>
  176.         <id>5</id>
  177.         <text><span class="style2">lipToICON ┬⌐1991 Brett Sher</span><span class="style1">
  178.  
  179. </span><span class="style2">Syntax</span><span class="style1">: clipToICON <iconName>
  180.  
  181. </span><span class="style2">Functionality</span><span class="style1">: clipToICON scales a PICT on the clipboard to ICON size and updates the named icon, creating it if it does not already exist in the stack.  ICON names of longer than 24 characters are not accepted.
  182.  
  183. </span><span class="style2">Demonstration</span><span class="style1">: To test the XCMD now, use HyperCardΓÇÖs paint tools to design an icon in the designated area below.  Then click the Example button.  Your art will be transformed into an ICON, and a button will appear displaying your new ICON.
  184.  
  185. </span><span class="style2">Credits</span><span class="style1">: Thanks to Tony Beruman for jumpstarting me into the wacky world of HyperCard externals.  This XCMD was developed using CompileIt! (written by Tom Pittman and distributed by Heizer Software).  I recommend CompileIt! as an inexpensive way to explore the Mac Toolbox.   I have included the source code (click the show source button).
  186.  
  187. </span><span class="style2">Warning:</span><span class="style1">  I make no warrantee as to the fitness of this XCMD.  In fact I'd be surprised if there wasnΓÇÖt some way of breaking it.  After all, its my first attempt at writing an XCMD. Use it at your peril.  Send  bug reports and feature requests to the address below.
  188.  
  189. </span><span class="style2">License:</span><span class="style1">  You are welcome to use this XCMD in your own noncommercial stacks, and to study the source code.  You may freely distribute this stack to others in its original form with all copyright notices intact.
  190.  
  191. However, if  you plan to </span><span class="style2">resell</span><span class="style1"> this XCMD as part of a commercial product, you must first obtain my written permission.
  192.  
  193. Direct your correspondence to:
  194.  
  195.                Brett Sher
  196.                808 Gale Drive
  197.                Campbell, CA 95008
  198. </span></text>
  199.     </content>
  200.     <content>
  201.         <layer>card</layer>
  202.         <id>1</id>
  203.         <text>Draw your ICON here</text>
  204.     </content>
  205.     <content>
  206.         <layer>background</layer>
  207.         <id>14</id>
  208.         <text>-- clipToIcon 1.0, ┬⌐ 1991 Brett Sher, Campbell, CA, All Rights Reserved
  209. -- XCMD clipToIcon sets the bit image of the ICON resource named by the parameter <iconName> to
  210. -- the image of a PICT on the clipboard. If the PICT is not exactly 32 x 32 bits, it is scaled to fit.
  211. -- If there is not already an ICON named <iconName>, one will be added to the current stack.
  212. -- <iconName> is not allowed to be empty or exceed 24 characters.
  213.  
  214. global iconRect:Record [8]     -- 4  longInts
  215. global pictHndl:Pointer           -- handle to PICT on clipboard
  216. global iconHndl:Pointer           -- handle to ICON resource
  217. global iconDataHndl:Pointer    -- handle to new ICON image
  218. global graphportPtr:Pointer   -- pointer to an offscreen graphport
  219. global oldPortPtr:Pointer       -- pointer to old grafport
  220.  
  221. on clipToIcon iconName
  222.   
  223.   if iconName is "?" then return info()
  224.   if iconName is "!" then return version()
  225.   if iconName is "" then return "ERROR: <iconName> was empty"
  226.   if length (iconName) > 24 then return "ERROR: <iconName> was longer than 24 characters"
  227.   
  228.   put "" into errorMsg
  229.   setRect iconRect,0,0,32,32
  230.   put newHandle(1) into pictHndl -- create a minimum size handle
  231.   put getScrap(pictHndl, "PICT", pictOffset) into thePictLength  -- get pictHandle from clipboard
  232.   if thePictLength < 0 then
  233.     put "ERROR: No PICT found on clipboard" into errorMsg
  234.   else
  235.     GetPort oldPortPtr -- save old grafport pointer
  236.     put NewPtr(112) into graphportPtr        -- It may only need 108 but a litte more shouldn't hurt
  237.     OpenPort graphportPtr
  238.     put iconRect into graphportPtr@.portRect
  239.     put iconRect into graphportPtr@.portBits.bounds
  240.     put 4 into graphportPtr@.portBits.rowbytes
  241.     put newHandle(128) into iconDataHndl      -- allocate space for our ICON graphic
  242.     hLock iconDataHndl
  243.     put iconDataHndl@ into graphportPtr@.portBits.baseAddr -- redirect quickDraw to our ICON data
  244.     
  245.     SetPort graphportPtr
  246.     DrawPicture pictHndl, iconRect
  247.     
  248.     put Get1NamedResource("ICON",iconName) into iconHndl -- try to get existing ICON of same name
  249.     put resError() into resErrNum
  250.     if iconHndl <> 0 then -- We already have an ICON of this name
  251.       
  252.       BlockMove iconDataHndl@, iconHndl@,128 -- poke new bit image into our old icon
  253.       
  254.     else -- we need to create a new ICON
  255.       
  256.       repeat with i = 1 to 100
  257.         put UniqueID("ICON") into iconID
  258.         if iconID> 127 then exit repeat -- guarantee no conflict with system resources
  259.       end repeat
  260.       if i > 99 then
  261.         put "ERROR: Couldn't Generate unique id for new ICON" into ErrorMsg
  262.       else
  263.         AddResource iconDataHndl, "ICON", iconID, iconName -- iconDataHndl assigns our new bit image
  264.         put resError() into resErrNum
  265.         put Get1Resource("ICON",iconID) into iconHndl
  266.       end if
  267.       
  268.     end if
  269.     
  270.     -- iconHandle now points to our ICON with an updated image
  271.     
  272.     if resErrNum = 0 and ErrorMsg = "" then
  273.       SetResAttrs iconHndl,resChanged + resPurgeable
  274.       WriteResource iconHndl
  275.       put resError() into resErrNum
  276.       if resErrNum <> 0 then put ResErrMsg(resErrNum) into ErrorMsg
  277.       ReleaseResource iconHndl
  278.     else
  279.       put ResErrMsg(resErrNum) into ErrorMsg
  280.     end if
  281.   end if
  282.   
  283.   hUnlock iconDataHndl
  284.   ClosePort graphportPtr
  285.   DisposPtr graphportPtr
  286.   SetPort oldPortPtr -- restore quickdraw to hypercard's grafPort
  287.   DisposHandle iconDataHndl
  288.   DisposHandle pictHndl
  289.   
  290.   return ErrorMsg
  291. end clipToIcon
  292.  
  293. function version
  294.   return  "clipToIcon 1.0, ┬⌐ 1991 Brett Sher, Campbell, CA, All Rights Reserved" & return &┬¼
  295.   "Last revised: Saturday 10/1/91"
  296. end version
  297.  
  298. function info
  299.   return "Applies PICT on clipboard to an ICON. Syntax: clipToIcon <iconName>" & return &┬¼
  300.   "A new ICON is created, if the named ICON  does not already exist."
  301. end info
  302.  
  303. function ResErrMsg x
  304.   if x = -192 then return "Resource not found"
  305.   else if x = -193 then return "Resource file not found"
  306.   else if x = -194 then return "AddResource failed"
  307.   else if x = -195 then return "RmveResource failed"
  308.   else if x = -196 then return "Operation prohibited by resource attribute"
  309.   else if x = -199 then return "Error reading resource map"
  310.   else if x = -34 then return "Disk Full"
  311.   else return "Unknown resource error" && x
  312. end ResErrMsg</text>
  313.     </content>
  314.     <name></name>
  315.     <script>on closeCard
  316. hide btn 1
  317. end closeCard</script>
  318. </card>
  319.  
  320.  
  321.